package com.kk.netty.nio.demo;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * 分散集中写
 */
public class TestScatteringWrites {
    public static void main(String[] args) {
        ByteBuffer b1 = StandardCharsets.UTF_8.encode ("hello");
        ByteBuffer b2 = StandardCharsets.UTF_8.encode ("world");
        ByteBuffer b3 = StandardCharsets.UTF_8.encode ("你好，世界");
        try (FileChannel file = new RandomAccessFile ("boot_netty/helloword/2parts.txt", "rw").getChannel ( )) {
            file.write (new ByteBuffer[]{b1, b2, b3});
        } catch (IOException e) {
            e.printStackTrace ( );
        }
    }
}
